package ac.github.os.internal.core.action.location

import ac.github.os.internal.core.action.ILocationAction
import ac.github.os.internal.core.config.StringConfig
import ac.github.os.internal.core.config.get
import ac.github.os.internal.core.objective.LocationObjective
import ac.github.os.internal.session.Cache
import ac.github.os.internal.session.Session
import org.bukkit.Sound
import taboolib.common.platform.Awake
import taboolib.common.platform.function.info

@Awake
class SoundAction : ILocationAction() {
    override fun onExecute(session: Session, cache: Cache, config: StringConfig) {

        val sound = config.get<Sound>("type", single = true)
        if (sound == null) {
            info("无效的Sound " + config.get<String>("type", single = true))
            return
        }
        val v = config.get("v", 1f)!!
        val p = config.get("p", 1f)!!
        cache.objectives.forEach {
            it as LocationObjective
            it.location.world!!.playSound(it.location, sound, v, p)
        }

    }

    override val namespace: String
        get() = "loc:sound"
}